import { defineStore } from "pinia";
import { Shop, ShopBanner } from "../api/index.js";
export const useListStore = defineStore("list", {
  state: () => {
    return {
      list: [],
      GuessLikeArr: [],
      bannerImg: [],
      // 四个分类
      Accessories: [],
      kitchenware: [],
      Garbage: [],
      Appliance: [],
    };
  },
  getters: {},
  actions: {
    getInfo(num, page) {
      Shop(num, page)
        .then((res) => {
          this.list = res.data.data.goodList;
          // console.log(res)

          this.GuessLikeArr = [];
          this.Accessories = [];
          this.kitchenware = [];
          this.Garbage = [];
          this.Appliance = [];
          this.list.forEach((item) => {
            if (item.islike === 1) {
              this.GuessLikeArr.push(item);
            }
            if (item.type === "家居\r\n饰品") {
              this.Accessories.push(item);
            } else if (item.type === "厨卫用品") {
              this.kitchenware.push(item);
            } else if (item.type === "垃圾处理") {
              this.Garbage.push(item);
            } else if (item.type === "家用电器") {
              this.Appliance.push(item);
            }
          });
        })
        .catch((err) => {
          console.log(err);
        });
      ShopBanner()
        .then((res) => {
          this.bannerImg = [];
          res.data.data.carouselList.forEach((item) => {
            this.bannerImg.push(item.photo);
          });
        })
        .catch((err) => {
          console.log(err);
        });
    },
  },
});
